<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>usr_07 - Vim Documentation</title>
<meta name="Generator" content="Vim/8.0">
<meta name="plugin-version" content="vim8.0">
<meta name="syntax" content="help">
<meta name="settings" content="no_pre,use_css,expand_tabs">
<link rel="stylesheet" href="style.css" type="text/css" />

<script src="jquery.min.js" type="text/javascript"></script>
<script src="mark-current-page.js" type="text/javascript"></script>
</head>

<body>

<header>

<div class="header">
  <a href="http://vim-jp.org/">vim-jp</a>
  / <a href="http://vim-jp.org/vimdoc-en/">vimdoc-en</a>
  / usr_07<br />
  <a name="top"></a><h1>usr_07 - Vim Documentation</h1>
  <a href="index.html">Return to main</a>

  <span class="EnglishJapaneseLink">
    <span class="CurrentLanguage">English</span>
  </span>
</div>
</header>

<nav>
<dl>

<dt>BASIC</dt>
<dd><ul>
<li><a href="quickref.html">quickref</a></li>
<li><a href="sponsor.html">sponsor</a></li>
</ul></dd>

<dt>USER MANUAL</dt>
<dd><ul>
<li><a href="usr_toc.html">usr_toc</a></li>
</ul></dd>

<dt>Getting Started</dt>
<dd><ul>
<li><a href="usr_01.html">usr_01</a></li>
<li><a href="usr_02.html">usr_02</a></li>
<li><a href="usr_03.html">usr_03</a></li>
<li><a href="usr_04.html">usr_04</a></li>
<li><a href="usr_05.html">usr_05</a></li>
<li><a href="usr_06.html">usr_06</a></li>
<li><a href="usr_07.html">usr_07</a></li>
<li><a href="usr_08.html">usr_08</a></li>
<li><a href="usr_09.html">usr_09</a></li>
<li><a href="usr_10.html">usr_10</a></li>
<li><a href="usr_11.html">usr_11</a></li>
<li><a href="usr_12.html">usr_12</a></li>
</ul></dd>

<dt>Editing Effectively</dt>
<dd><ul>
<li><a href="usr_20.html">usr_20</a></li>
<li><a href="usr_21.html">usr_21</a></li>
<li><a href="usr_22.html">usr_22</a></li>
<li><a href="usr_23.html">usr_23</a></li>
<li><a href="usr_24.html">usr_24</a></li>
<li><a href="usr_25.html">usr_25</a></li>
<li><a href="usr_26.html">usr_26</a></li>
<li><a href="usr_27.html">usr_27</a></li>
<li><a href="usr_28.html">usr_28</a></li>
<li><a href="usr_29.html">usr_29</a></li>
<li><a href="usr_30.html">usr_30</a></li>
<li><a href="usr_31.html">usr_31</a></li>
<li><a href="usr_32.html">usr_32</a></li>
</ul></dd>

<dt>Tuning Vim</dt>
<dd><ul>
<li><a href="usr_40.html">usr_40</a></li>
<li><a href="usr_41.html">usr_41</a></li>
<li><a href="usr_42.html">usr_42</a></li>
<li><a href="usr_43.html">usr_43</a></li>
<li><a href="usr_44.html">usr_44</a></li>
<li><a href="usr_45.html">usr_45</a></li>
</ul></dd>

<dt>Making Vim Run</dt>
<dd><ul>
<li><a href="usr_90.html">usr_90</a></li>
</ul></dd>

<dt>General subjects</dt>
<dd><ul>
<li><a href="intro.html">intro</a></li>
<li><a href="index.html">help</a></li>
<li><a href="helphelp.html">helphelp</a></li>
<li><a href="vimindex.html">index</a></li>
<li><a href="tags.html">tags</a></li>
<li><a href="howto.html">howto</a></li>
<li><a href="tips.html">tips</a></li>
<li><a href="message.html">message</a></li>
<li><a href="quotes.html">quotes</a></li>
<li><a href="todo.html">todo</a></li>
<li><a href="debug.html">debug</a></li>
<li><a href="develop.html">develop</a></li>
<li><a href="uganda.html">uganda</a></li>
</ul></dd>

<dt>Basic editing</dt>
<dd><ul>
<li><a href="starting.html">starting</a></li>
<li><a href="editing.html">editing</a></li>
<li><a href="motion.html">motion</a></li>
<li><a href="scroll.html">scroll</a></li>
<li><a href="insert.html">insert</a></li>
<li><a href="change.html">change</a></li>
<li><a href="indent.html">indent</a></li>
<li><a href="undo.html">undo</a></li>
<li><a href="repeat.html">repeat</a></li>
<li><a href="visual.html">visual</a></li>
<li><a href="various.html">various</a></li>
<li><a href="recover.html">recover</a></li>
</ul></dd>

<dt>Advanced editing</dt>
<dd><ul>
<li><a href="cmdline.html">cmdline</a></li>
<li><a href="options.html">options</a></li>
<li><a href="pattern.html">pattern</a></li>
<li><a href="map.html">map</a></li>
<li><a href="tagsrch.html">tagsrch</a></li>
<li><a href="quickfix.html">quickfix</a></li>
<li><a href="windows.html">windows</a></li>
<li><a href="tabpage.html">tabpage</a></li>
<li><a href="syntax.html">syntax</a></li>
<li><a href="spell.html">spell</a></li>
<li><a href="diff.html">diff</a></li>
<li><a href="autocmd.html">autocmd</a></li>
<li><a href="filetype.html">filetype</a></li>
<li><a href="eval.html">eval</a></li>
<li><a href="channel.html">channel</a></li>
<li><a href="fold.html">fold</a></li>
</ul></dd>

<dt>Special issues</dt>
<dd><ul>
<li><a href="print.html">print</a></li>
<li><a href="remote.html">remote</a></li>
<li><a href="term.html">term</a></li>
<li><a href="digraph.html">digraph</a></li>
<li><a href="mbyte.html">mbyte</a></li>
<li><a href="mlang.html">mlang</a></li>
<li><a href="arabic.html">arabic</a></li>
<li><a href="farsi.html">farsi</a></li>
<li><a href="hebrew.html">hebrew</a></li>
<li><a href="russian.html">russian</a></li>
<li><a href="ft_ada.html">ft_ada</a></li>
<li><a href="ft_sql.html">ft_sql</a></li>
<li><a href="hangulin.html">hangulin</a></li>
<li><a href="rileft.html">rileft</a></li>
</ul></dd>

<dt>GUI</dt>
<dd><ul>
<li><a href="gui.html">gui</a></li>
<li><a href="gui_w32.html">gui_w32</a></li>
<li><a href="gui_x11.html">gui_x11</a></li>
</ul></dd>

<dt>Interfaces</dt>
<dd><ul>
<li><a href="if_cscop.html">if_cscop</a></li>
<li><a href="if_lua.html">if_lua</a></li>
<li><a href="if_mzsch.html">if_mzsch</a></li>
<li><a href="if_perl.html">if_perl</a></li>
<li><a href="if_pyth.html">if_pyth</a></li>
<li><a href="if_tcl.html">if_tcl</a></li>
<li><a href="if_ole.html">if_ole</a></li>
<li><a href="if_ruby.html">if_ruby</a></li>
<li><a href="debugger.html">debugger</a></li>
<li><a href="workshop.html">workshop</a></li>
<li><a href="netbeans.html">netbeans</a></li>
<li><a href="sign.html">sign</a></li>
</ul></dd>

<dt>Versions</dt>
<dd><ul>
<li><a href="vi_diff.html">vi_diff</a></li>
<li><a href="version4.html">version4</a></li>
<li><a href="version5.html">version5</a></li>
<li><a href="version6.html">version6</a></li>
<li><a href="version7.html">version7</a></li>
<li><a href="version8.html">version8</a></li>
</ul></dd>

<dt>Remarks about specific systems</dt>
<dd><ul>
<li><a href="os_390.html">os_390</a></li>
<li><a href="os_amiga.html">os_amiga</a></li>
<li><a href="os_beos.html">os_beos</a></li>
<li><a href="os_dos.html">os_dos</a></li>
<li><a href="os_mac.html">os_mac</a></li>
<li><a href="os_mint.html">os_mint</a></li>
<li><a href="os_msdos.html">os_msdos</a></li>
<li><a href="os_os2.html">os_os2</a></li>
<li><a href="os_qnx.html">os_qnx</a></li>
<li><a href="os_risc.html">os_risc</a></li>
<li><a href="os_unix.html">os_unix</a></li>
<li><a href="os_vms.html">os_vms</a></li>
<li><a href="os_win32.html">os_win32</a></li>
</ul></dd>

<dt>Standard plugins</dt>
<dd><ul>
<li><a href="pi_getscript.html">pi_getscript</a></li>
<li><a href="pi_gzip.html">pi_gzip</a></li>
<li><a href="pi_logipat.html">pi_logipat</a></li>
<li><a href="pi_netrw.html">pi_netrw</a></li>
<li><a href="pi_paren.html">pi_paren</a></li>
<li><a href="pi_tar.html">pi_tar</a></li>
<li><a href="pi_vimball.html">pi_vimball</a></li>
<li><a href="pi_zip.html">pi_zip</a></li>
</ul></dd>

<dt>Filetype plugins</dt>
<dd><ul>
<li><a href="pi_spec.html">pi_spec</a></li>
</ul></dd>

<dt>Others</dt>
<dd><ul>
<li><a href="vim_faq.html">vim_faq</a></li>
</ul></dd>

</dl>
</nav>

<article class="Vimdoc VimdocJa">
<div id='vimCodeElement'>
<a class="Constant" href="usr_07.html" name="usr_07.txt">usr_07.txt</a>&nbsp;&nbsp;&nbsp;&nbsp;For&nbsp;<span class="Identifier">Vim version 8.0.</span>&nbsp;&nbsp;Last change: 2006 Apr 24<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VIM USER MANUAL - by Bram Moolenaar<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Editing more than one file<br>
<br>
<br>
No matter how many files you have, you can edit them without leaving Vim.<br>
Define a list of files to work on and jump from one to the other.&nbsp;&nbsp;Copy text<br>
from one file and put it in another one.<br>
<br>
<a class="Identifier" href="usr_07.html#07.1">07.1</a>&nbsp;&nbsp;Edit another file<br>
<a class="Identifier" href="usr_07.html#07.2">07.2</a>&nbsp;&nbsp;A list of files<br>
<a class="Identifier" href="usr_07.html#07.3">07.3</a>&nbsp;&nbsp;Jumping from file to file<br>
<a class="Identifier" href="usr_07.html#07.4">07.4</a>&nbsp;&nbsp;Backup files<br>
<a class="Identifier" href="usr_07.html#07.5">07.5</a>&nbsp;&nbsp;Copy text between files<br>
<a class="Identifier" href="usr_07.html#07.6">07.6</a>&nbsp;&nbsp;Viewing a file<br>
<a class="Identifier" href="usr_07.html#07.7">07.7</a>&nbsp;&nbsp;Changing the file name<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; Next chapter:&nbsp;<a class="Identifier" href="usr_08.html">usr_08.txt</a>&nbsp;&nbsp;Splitting windows<br>
&nbsp;Previous chapter:&nbsp;<a class="Identifier" href="usr_06.html">usr_06.txt</a>&nbsp;&nbsp;Using syntax highlighting<br>
Table of contents:&nbsp;<a class="Identifier" href="usr_toc.html">usr_toc.txt</a><br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_07.html#07.1" name="07.1">07.1</a>&nbsp;&nbsp;Edit another file<br>
<br>
So far you had to start Vim for every file you wanted to edit.&nbsp;&nbsp;There is a<br>
simpler way.&nbsp;&nbsp;To start editing another file, use this command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:edit foo.txt</div>
<br>
You can use any file name instead of &quot;foo.txt&quot;.&nbsp;&nbsp;Vim will close the current<br>
file and open the new one.&nbsp;&nbsp;If the current file has unsaved changes, however,<br>
Vim displays an error message and does not open the new file:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">E37: No write since last change (use ! to override)</span><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Todo">Note</span>:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Vim puts an error ID at the start of each error message.&nbsp;&nbsp;If you do<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;not understand the message or what caused it, look in the help system<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for this ID.&nbsp;&nbsp;In this case:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:help E37</div>
<br>
At this point, you have a number of alternatives.&nbsp;&nbsp;You can write the file<br>
using this command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:write</div>
<br>
Or you can force Vim to discard your changes and edit the new file, using the<br>
force (!) character:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:edit! foo.txt</div>
<br>
If you want to edit another file, but not write the changes in the current<br>
file yet, you can make it hidden:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:hide edit foo.txt</div>
<br>
The text with changes is still there, but you can't see it.&nbsp;&nbsp;This is further<br>
explained in section&nbsp;<a class="Identifier" href="usr_22.html#22.4">22.4</a>: The buffer list.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_07.html#07.2" name="07.2">07.2</a>&nbsp;&nbsp;A list of files<br>
<br>
You can start Vim to edit a sequence of files.&nbsp;&nbsp;For example:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vim one.c two.c three.c</div>
<br>
This command starts Vim and tells it that you will be editing three files.<br>
Vim displays just the first file.&nbsp;&nbsp;After you have done your thing in this<br>
file, to edit the next file you use this command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:next</div>
<br>
If you have unsaved changes in the current file, you will get an error<br>
message and the &quot;:next&quot; will not work.&nbsp;&nbsp;This is the same problem as with<br>
&quot;:edit&quot; mentioned in the previous section.&nbsp;&nbsp;To abandon the changes:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:next!</div>
<br>
But mostly you want to save the changes and move on to the next file.&nbsp;&nbsp;There<br>
is a special command for this:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:wnext</div>
<br>
This does the same as using two separate commands:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:write<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:next</div>
<br>
<br>
WHERE AM I?<br>
<br>
To see which file in the argument list you are editing, look in the window<br>
title.&nbsp;&nbsp;It should show something like &quot;(2 of 3)&quot;.&nbsp;&nbsp;This means you are editing<br>
the second file out of three files.<br>
&nbsp;&nbsp; If you want to see the list of files, use this command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:args</div>
<br>
This is short for &quot;arguments&quot;.&nbsp;&nbsp;The output might look like this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">one.c [two.c] three.c</span><br>
<br>
These are the files you started Vim with.&nbsp;&nbsp;The one you are currently editing,<br>
&quot;two.c&quot;, is in square brackets.<br>
<br>
<br>
MOVING TO OTHER ARGUMENTS<br>
<br>
To go back one file:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:previous</div>
<br>
This is just like the &quot;:next&quot; command, except that it moves in the other<br>
direction.&nbsp;&nbsp;Again, there is a shortcut command for when you want to write the<br>
file first:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:wprevious</div>
<br>
To move to the very last file in the list:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:last</div>
<br>
And to move back to the first one again:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:first</div>
<br>
There is no &quot;:wlast&quot; or &quot;:wfirst&quot; command though!<br>
<br>
You can use a count for &quot;:next&quot; and &quot;:previous&quot;.&nbsp;&nbsp;To skip two files forward:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:2next</div>
<br>
<br>
AUTOMATIC WRITING<br>
<br>
When moving around the files and making changes, you have to remember to use<br>
&quot;:write&quot;.&nbsp;&nbsp;Otherwise you will get an error message.&nbsp;&nbsp;If you are sure you<br>
always want to write modified files, you can tell Vim to automatically write<br>
them:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set autowrite</div>
<br>
When you are editing a file which you may not want to write, switch it off<br>
again:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set noautowrite</div>
<br>
<br>
EDITING ANOTHER LIST OF FILES<br>
<br>
You can redefine the list of files without the need to exit Vim and start it<br>
again.&nbsp;&nbsp;Use this command to edit three other files:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:args five.c six.c seven.h</div>
<br>
Or use a wildcard, like it's used in the shell:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:args *.txt</div>
<br>
Vim will take you to the first file in the list.&nbsp;&nbsp;Again, if the current file<br>
has changes, you can either write the file first, or use &quot;:args!&quot; (with !<br>
added) to abandon the changes.<br>
<br>
<br>
DID YOU EDIT THE LAST FILE?<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="Constant" href="usr_07.html#arglist-quit" name="arglist-quit">arglist-quit</a><br>
When you use a list of files, Vim assumes you want to edit them all.&nbsp;&nbsp;To<br>
protect you from exiting too early, you will get this error when you didn't<br>
edit the last file in the list yet:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">E173: 46 more files to edit</span><br>
<br>
If you really want to exit, just do it again.&nbsp;&nbsp;Then it will work (but not when<br>
you did other commands in between).<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_07.html#07.3" name="07.3">07.3</a>&nbsp;&nbsp;Jumping from file to file<br>
<br>
To quickly jump between two files, press&nbsp;<span class="Special">CTRL-^</span>&nbsp;(on English-US keyboards the ^<br>
is above the 6 key).&nbsp;&nbsp;Example:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:args one.c two.c three.c</div>
<br>
You are now in one.c.<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:next</div>
<br>
Now you are in two.c.&nbsp;&nbsp;Now use&nbsp;<span class="Special">CTRL-^</span>&nbsp;to go back to one.c.&nbsp;&nbsp;Another&nbsp;<span class="Special">CTRL-^</span>&nbsp;and<br>
you are back in two.c.&nbsp;&nbsp;Another&nbsp;<span class="Special">CTRL-^</span>&nbsp;and you are in one.c again.&nbsp;&nbsp;If you now<br>
do:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:next</div>
<br>
You are in three.c.&nbsp;&nbsp;Notice that the&nbsp;<span class="Special">CTRL-^</span>&nbsp;command does not change the idea<br>
of where you are in the list of files.&nbsp;&nbsp;Only commands like &quot;:next&quot; and<br>
&quot;:previous&quot; do that.<br>
<br>
The file you were previously editing is called the &quot;alternate&quot; file.&nbsp;&nbsp;When you<br>
just started Vim&nbsp;<span class="Special">CTRL-^</span>&nbsp;will not work, since there isn't a previous file.<br>
<br>
<br>
PREDEFINED MARKS<br>
<br>
After jumping to another file, you can use two predefined marks which are very<br>
useful:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`&quot;</div>
<br>
This takes you to the position where the cursor was when you left the file.<br>
Another mark that is remembered is the position where you made the last<br>
change:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`.</div>
<br>
Suppose you are editing the file &quot;one.txt&quot;.&nbsp;&nbsp;Somewhere halfway the file you<br>
use &quot;x&quot; to delete a character.&nbsp;&nbsp;Then you go to the last line with &quot;G&quot; and<br>
write the file with &quot;:w&quot;.&nbsp;&nbsp;You edit several other files, and then use &quot;:edit<br>
one.txt&quot; to come back to &quot;one.txt&quot;.&nbsp;&nbsp;If you now use `&quot; Vim jumps to the last<br>
line of the file.&nbsp;&nbsp;Using `. takes you to the position where you deleted the<br>
character.&nbsp;&nbsp;Even when you move around in the file `&quot; and `. will take you to<br>
the remembered position.&nbsp;&nbsp;At least until you make another change or leave the<br>
file.<br>
<br>
<br>
FILE MARKS<br>
<br>
In chapter 4 was explained how you can place a mark in a file with &quot;mx&quot; and<br>
jump to that position with &quot;`x&quot;.&nbsp;&nbsp;That works within one file.&nbsp;&nbsp;If you edit<br>
another file and place marks there, these are specific for that file.&nbsp;&nbsp;Thus<br>
each file has its own set of marks, they are local to the file.<br>
&nbsp;&nbsp; So far we were using marks with a lowercase letter.&nbsp;&nbsp;There are also marks<br>
with an uppercase letter.&nbsp;&nbsp;These are global, they can be used from any file.<br>
For example suppose that we are editing the file &quot;foo.txt&quot;.&nbsp;&nbsp;Go to halfway the<br>
file (&quot;50%&quot;) and place the F mark there (F for foo):<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;50%mF</div>
<br>
Now edit the file &quot;bar.txt&quot; and place the B mark (B for bar) at its last line:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GmB</div>
<br>
Now you can use the &quot;'F&quot; command to jump back to halfway foo.txt.&nbsp;&nbsp;Or edit yet<br>
another file, type &quot;'B&quot; and you are at the end of bar.txt again.<br>
<br>
The file marks are remembered until they are placed somewhere else.&nbsp;&nbsp;Thus you<br>
can place the mark, do hours of editing and still be able to jump back to that<br>
mark.<br>
&nbsp;&nbsp; It's often useful to think of a simple connection between the mark letter<br>
and where it is placed.&nbsp;&nbsp;For example, use the H mark in a header file, M in<br>
a Makefile and C in a C code file.<br>
<br>
To see where a specific mark is, give an argument to the &quot;:marks&quot; command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:marks M</div>
<br>
You can also give several arguments:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:marks MCP</div>
<br>
Don't forget that you can use&nbsp;<span class="Special">CTRL-O</span>&nbsp;and&nbsp;<span class="Special">CTRL-I</span>&nbsp;to jump to older and newer<br>
positions without placing marks there.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_07.html#07.4" name="07.4">07.4</a>&nbsp;&nbsp;Backup files<br>
<br>
Usually Vim does not produce a backup file.&nbsp;&nbsp;If you want to have one, all you<br>
need to do is execute the following command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set backup</div>
<br>
The name of the backup file is the original file with a&nbsp;&nbsp;~&nbsp;&nbsp;added to the end.<br>
If your file is named data.txt, for example, the backup file name is<br>
data.txt~.<br>
&nbsp;&nbsp; If you do not like the fact that the backup files end with ~, you can<br>
change the extension:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set backupext=.bak</div>
<br>
This will use data.txt.bak instead of data.txt~.<br>
&nbsp;&nbsp; Another option that matters here is&nbsp;<a class="Type" href="options.html#'backupdir'">'backupdir'</a>.&nbsp;&nbsp;It specifies where the<br>
backup file is written.&nbsp;&nbsp;The default, to write the backup in the same<br>
directory as the original file, will mostly be the right thing.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Todo">Note</span>:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;When the&nbsp;<a class="Type" href="options.html#'backup'">'backup'</a>&nbsp;option isn't set but the&nbsp;<a class="Type" href="options.html#'writebackup'">'writebackup'</a>&nbsp;is, Vim will<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;still create a backup file.&nbsp;&nbsp;However, it is deleted as soon as writing<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the file was completed successfully.&nbsp;&nbsp;This functions as a safety<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;against losing your original file when writing fails in some way (disk<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;full is the most common cause; being hit by lightning might be<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;another, although less common).<br>
<br>
<br>
KEEPING THE ORIGINAL FILE<br>
<br>
If you are editing source files, you might want to keep the file before you<br>
make any changes.&nbsp;&nbsp;But the backup file will be overwritten each time you write<br>
the file.&nbsp;&nbsp;Thus it only contains the previous version, not the first one.<br>
&nbsp;&nbsp; To make Vim keep the original file, set the&nbsp;<a class="Type" href="options.html#'patchmode'">'patchmode'</a>&nbsp;option.&nbsp;&nbsp;This<br>
specifies the extension used for the first backup of a changed file.&nbsp;&nbsp;Usually<br>
you would do this:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set patchmode=.orig</div>
<br>
When you now edit the file data.txt for the first time, make changes and write<br>
the file, Vim will keep a copy of the unchanged file under the name<br>
&quot;data.txt.orig&quot;.<br>
&nbsp;&nbsp; If you make further changes to the file, Vim will notice that<br>
&quot;data.txt.orig&quot; already exists and leave it alone.&nbsp;&nbsp;Further backup files will<br>
then be called &quot;data.txt~&quot; (or whatever you specified with&nbsp;<a class="Type" href="options.html#'backupext'">'backupext'</a>).<br>
&nbsp;&nbsp; If you leave&nbsp;<a class="Type" href="options.html#'patchmode'">'patchmode'</a>&nbsp;empty (that is the default), the original file<br>
will not be kept.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_07.html#07.5" name="07.5">07.5</a>&nbsp;&nbsp;Copy text between files<br>
<br>
This explains how to copy text from one file to another.&nbsp;&nbsp;Let's start with a<br>
simple example.&nbsp;&nbsp;Edit the file that contains the text you want to copy.&nbsp;&nbsp;Move<br>
the cursor to the start of the text and press &quot;v&quot;.&nbsp;&nbsp;This starts Visual mode.<br>
Now move the cursor to the end of the text and press &quot;y&quot;.&nbsp;&nbsp;This yanks (copies)<br>
the selected text.<br>
&nbsp;&nbsp; To copy the above paragraph, you would do:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:edit thisfile<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/This<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vjjjj$y</div>
<br>
Now edit the file you want to put the text in.&nbsp;&nbsp;Move the cursor to the<br>
character where you want the text to appear after.&nbsp;&nbsp;Use &quot;p&quot; to put the text<br>
there.<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:edit otherfile<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/There<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</div>
<br>
Of course you can use many other commands to yank the text.&nbsp;&nbsp;For example, to<br>
select whole lines start Visual mode with &quot;V&quot;.&nbsp;&nbsp;Or use&nbsp;<span class="Special">CTRL-V</span>&nbsp;to select a<br>
rectangular block.&nbsp;&nbsp;Or use &quot;Y&quot; to yank a single line, &quot;yaw&quot; to yank-a-word,<br>
etc.<br>
&nbsp;&nbsp; The &quot;p&quot; command puts the text after the cursor.&nbsp;&nbsp;Use &quot;P&quot; to put the text<br>
before the cursor.&nbsp;&nbsp;Notice that Vim remembers if you yanked a whole line or a<br>
block, and puts it back that way.<br>
<br>
<br>
USING REGISTERS<br>
<br>
When you want to copy several pieces of text from one file to another, having<br>
to switch between the files and writing the target file takes a lot of time.<br>
To avoid this, copy each piece of text to its own register.<br>
&nbsp;&nbsp; A register is a place where Vim stores text.&nbsp;&nbsp;Here we will use the<br>
registers named a to z (later you will find out there are others).&nbsp;&nbsp;Let's copy<br>
a sentence to the f register (f for First):<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;fyas</div>
<br>
The &quot;yas&quot; command yanks a sentence like before.&nbsp;&nbsp;It's the &quot;f that tells Vim<br>
the text should be place in the f register.&nbsp;&nbsp;This must come just before the<br>
yank command.<br>
&nbsp;&nbsp; Now yank three whole lines to the l register (l for line):<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;l3Y</div>
<br>
The count could be before the &quot;l just as well.&nbsp;&nbsp;To yank a block of text to the<br>
b (for block) register:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CTRL-Vjjww&quot;by</div>
<br>
Notice that the register specification &quot;b is just before the &quot;y&quot; command.<br>
This is required.&nbsp;&nbsp;If you would have put it before the &quot;w&quot; command, it would<br>
not have worked.<br>
&nbsp;&nbsp; Now you have three pieces of text in the f, l and b registers.&nbsp;&nbsp;Edit<br>
another file, move around and place the text where you want it:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;fp</div>
<br>
Again, the register specification &quot;f comes before the &quot;p&quot; command.<br>
&nbsp;&nbsp; You can put the registers in any order.&nbsp;&nbsp;And the text stays in the register<br>
until you yank something else into it.&nbsp;&nbsp;Thus you can put it as many times as<br>
you like.<br>
<br>
When you delete text, you can also specify a register.&nbsp;&nbsp;Use this to move<br>
several pieces of text around.&nbsp;&nbsp;For example, to delete-a-word and write it in<br>
the w register:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;wdaw</div>
<br>
Again, the register specification comes before the delete command &quot;d&quot;.<br>
<br>
<br>
APPENDING TO A FILE<br>
<br>
When collecting lines of text into one file, you can use this command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:write &gt;&gt; logfile</div>
<br>
This will write the text of the current file to the end of &quot;logfile&quot;.&nbsp;&nbsp;Thus it<br>
is appended.&nbsp;&nbsp;This avoids that you have to copy the lines, edit the log file<br>
and put them there.&nbsp;&nbsp;Thus you save two steps.&nbsp;&nbsp;But you can only append to the<br>
end of a file.<br>
&nbsp;&nbsp; To append only a few lines, select them in Visual mode before typing<br>
&quot;:write&quot;.&nbsp;&nbsp;In chapter 10 you will learn other ways to select a range of lines.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_07.html#07.6" name="07.6">07.6</a>&nbsp;&nbsp;Viewing a file<br>
<br>
Sometimes you only want to see what a file contains, without the intention to<br>
ever write it back.&nbsp;&nbsp;There is the risk that you type &quot;:w&quot; without thinking and<br>
overwrite the original file anyway.&nbsp;&nbsp;To avoid this, edit the file read-only.<br>
&nbsp;&nbsp; To start Vim in readonly mode, use this command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vim -R file</div>
<br>
On Unix this command should do the same thing:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;view file</div>
<br>
You are now editing &quot;file&quot; in read-only mode.&nbsp;&nbsp;When you try using &quot;:w&quot; you<br>
will get an error message and the file won't be written.<br>
&nbsp;&nbsp; When you try to make a change to the file Vim will give you a warning:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">W10: Warning: Changing a readonly file</span><br>
<br>
The change will be done though.&nbsp;&nbsp;This allows for formatting the file, for<br>
example, to be able to read it easily.<br>
&nbsp;&nbsp; If you make changes to a file and forgot that it was read-only, you can<br>
still write it.&nbsp;&nbsp;Add the ! to the write command to force writing.<br>
<br>
If you really want to forbid making changes in a file, do this:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vim -M file</div>
<br>
Now every attempt to change the text will fail.&nbsp;&nbsp;The help files are like this,<br>
for example.&nbsp;&nbsp;If you try to make a change you get this error message:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">E21: Cannot make changes, 'modifiable' is off</span><br>
<br>
You could use the -M argument to setup Vim to work in a viewer mode.&nbsp;&nbsp;This is<br>
only voluntary though, since these commands will remove the protection:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set modifiable<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set write</div>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_07.html#07.7" name="07.7">07.7</a>&nbsp;&nbsp;Changing the file name<br>
<br>
A clever way to start editing a new file is by using an existing file that<br>
contains most of what you need.&nbsp;&nbsp;For example, you start writing a new program<br>
to move a file.&nbsp;&nbsp;You know that you already have a program that copies a file,<br>
thus you start with:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:edit copy.c</div>
<br>
You can delete the stuff you don't need.&nbsp;&nbsp;Now you need to save the file under<br>
a new name.&nbsp;&nbsp;The &quot;:saveas&quot; command can be used for this:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:saveas move.c</div>
<br>
Vim will write the file under the given name, and edit that file.&nbsp;&nbsp;Thus the<br>
next time you do &quot;:write&quot;, it will write &quot;move.c&quot;.&nbsp;&nbsp;&quot;copy.c&quot; remains<br>
unmodified.<br>
&nbsp;&nbsp; When you want to change the name of the file you are editing, but don't<br>
want to write the file, you can use this command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:file move.c</div>
<br>
Vim will mark the file as &quot;not edited&quot;.&nbsp;&nbsp;This means that Vim knows this is not<br>
the file you started editing.&nbsp;&nbsp;When you try to write the file, you might get<br>
this message:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">E13: File exists (use ! to override)</span><br>
<br>
This protects you from accidentally overwriting another file.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<br>
Next chapter:&nbsp;<a class="Identifier" href="usr_08.html">usr_08.txt</a>&nbsp;&nbsp;Splitting windows<br>
<br>
Copyright: see&nbsp;<a class="Identifier" href="usr_01.html#manual-copyright">manual-copyright</a>&nbsp;&nbsp;vim:tw=78:ts=8:ft=help:norl:<br>
</div>

</article>

<footer>
<a href="#top">Return to the top</a> - <a href="index.html">Return to main</a>
<span class="EnglishJapaneseLink">
  <span class="CurrentLanguage">English</span>
</span>
<br />
<div style="text-align:right;">
Hosted by <a href="https://github.com/vim-jp/vimdoc-en">vimdoc-en project</a><br />
If you met any problem, please report it to <a href="https://github.com/vim-jp/vimdoc-en/issues">issue</a>.<br />
</div>
</footer>

<!--<script src="js/check-referrer.js" type="text/javascript"></script>-->

</body>
</html>
<!-- vim:set ts=8 sts=2 sw=2 tw=0 et: -->
